package com.fengye.school.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.data.domain.Page;

import java.util.List;

@Data
@AllArgsConstructor
public class PageVO<T> {
    /*总页数*/
    private Long total;

    /*当前页码*/
    private Integer page;

    /*当前页数量*/
    private Integer size;

    /*当前页的数据*/
    private List<T> content;

    public static <T> PageVO<T> build(Page<T> pages){
        return new PageVO<>(
                pages.getTotalElements(),
                pages.getTotalPages(),
                pages.getSize(),
                pages.getContent());
    }

    public static <T> PageVO<T> build(Page<?> pages, List<T> list) {
        return new PageVO<>(
                pages.getTotalElements(),
                pages.getTotalPages(),
                pages.getSize(),
                list
        );
    }
}
